<?php
/* @var $this ProductAdminController */
/* @var $model DndBoxanhfoodProduct */
/* @var $form CActiveForm */
?>
    <link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/jqwidgets/jquery.datetimepicker.css" type="text/css" />
    <link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/jqwidgets/jqxdatetimeinput.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/jqwidgets/jqxcalendar.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/jqwidgets/globalization/globalize.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/jqwidgets/jquery.datetimepicker.js"></script>
    <script>
        $(document).ready(function () {               
            $("#on_sale_start").datetimepicker({format:'Y-m-d H:i'});
            $("#on_sale_end").datetimepicker({format:'Y-m-d H:i'});
        });
    function convertandcheck(){
        var tmp;
        var value = '';
        var total = document.frmmain.Product_on_sale.value;
        total = total.split(',');
        for (tmp in total) {
            value = value + total[tmp];
        }
        value = parseInt(value);
        return value;
    }
    function FormatNumber(nStr) {
        nStr += '';
        var x = nStr.split(',');
        var x1 = x[0];
        var x2 = x.length > 1 ? ',' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }
    function checkAmount(obj,event) {
        var k;
        if(navigator.appName == "Netscape")
            k = event.which;
        else
            k = event.keyCode;
        if(k==37||k==39||k==9||k==36||k==46)//left right tab home delete
            return;
        var value = convertandcheck();
        if (value != "" && !isNaN(value)) {
            var txt1 = FormatNumber(value);
            document.frmmain.Product_on_sale.value = txt1;
            return;
        } else {
            document.frmmain.Product_on_sale.value = "";
            return;
        }
    }
    </script>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'dnd-product-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
    // 'enableClientValidation'=>true,
    'htmlOptions' => array('enctype' => 'multipart/form-data','name'=>'frmmain',),
)); ?>


	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'description'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'packing'); ?>
		<?php echo $form->textField($model,'packing',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'packing'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'in_stock'); ?>
		<?php echo $form->textField($model,'in_stock',array('size'=>11,'maxlength'=>11)); ?>
		<?php echo $form->error($model,'in_stock'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'on_sale'); ?>
		<?php $model->on_sale = ($model->on_sale ? number_format($model->on_sale,0) : '');?>
		<?php echo $form->textField($model,'on_sale',array('size'=>20,'maxlength'=>20,'onkeyup'=>'checkAmount(this,event);')); ?>
		<?php echo $form->error($model,'on_sale'); ?>
	</div>

	<div class="row">
        <?php echo $form->labelEx($model,'on_sale_start'); ?>
		<?php echo $form->textField($model,'on_sale_start',array('id'=>'on_sale_start')); ?>
		<?php echo $form->error($model,'on_sale_start'); ?>
	</div>

	<div class="row">
        <?php echo $form->labelEx($model,'on_sale_end'); ?>
		<?php echo $form->textField($model,'on_sale_end',array('id'=>'on_sale_end')); ?>
		<?php echo $form->error($model,'on_sale_end'); ?>
	</div>

	<!--div class="row">
		<?php echo $form->labelEx($model,'creation_datetime'); ?>
		<?php echo $form->textField($model,'creation_datetime'); ?>
		<?php echo $form->error($model,'creation_datetime'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'last_update'); ?>
		<?php echo $form->textField($model,'last_update'); ?>
		<?php echo $form->error($model,'last_update'); ?>
	</div-->

	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
        <?php echo CHtml::dropDownList('Product[status]', 'status',array('1'=>'Đang bán','0'=>'Ngưng bán')); ?>
		<?php echo $form->error($model,'status'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'category_id'); ?>
        <?php echo CHtml::dropDownList('Product[category_id]', 'category_id',  CHtml::listData(Category::model()->findAll("status='1'"),'id','name')); ?>
		<?php echo $form->error($model,'category_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'image_'); ?>
		<?php echo $form->fileField($model, 'image_'); ?>
		<?php echo $form->error($model,'image_'); ?>
	</div>

	<!--div class="row">
		<?php echo $form->labelEx($model,'banner'); ?>
		<?php echo $form->textField($model,'banner',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'banner'); ?>
	</div-->

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Tạo' : 'Lưu'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->